package com.pd.backend.service.impl;

import com.pd.backend.entity.PdTransportTripsTruckDriver;
import com.pd.backend.dao.PdTransportTripsTruckDriverDao;
import com.pd.backend.service.PdTransportTripsTruckDriverService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 车次与车辆和司机关联表(PdTransportTripsTruckDriver)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:36
 */
@Service("pdTransportTripsTruckDriverService")
public class PdTransportTripsTruckDriverServiceImpl implements PdTransportTripsTruckDriverService {
    @Resource
    private PdTransportTripsTruckDriverDao pdTransportTripsTruckDriverDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdTransportTripsTruckDriver queryById(String id) {
        return this.pdTransportTripsTruckDriverDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdTransportTripsTruckDriver 筛选条件
     * @param pageRequest                 分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdTransportTripsTruckDriver> queryByPage(PdTransportTripsTruckDriver pdTransportTripsTruckDriver, PageRequest pageRequest) {
        long total = this.pdTransportTripsTruckDriverDao.count(pdTransportTripsTruckDriver);
        return new PageImpl<>(this.pdTransportTripsTruckDriverDao.queryAllByLimit(pdTransportTripsTruckDriver, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdTransportTripsTruckDriver 实例对象
     * @return 实例对象
     */
    @Override
    public PdTransportTripsTruckDriver insert(PdTransportTripsTruckDriver pdTransportTripsTruckDriver) {
        this.pdTransportTripsTruckDriverDao.insert(pdTransportTripsTruckDriver);
        return pdTransportTripsTruckDriver;
    }

    /**
     * 修改数据
     *
     * @param pdTransportTripsTruckDriver 实例对象
     * @return 实例对象
     */
    @Override
    public PdTransportTripsTruckDriver update(PdTransportTripsTruckDriver pdTransportTripsTruckDriver) {
        this.pdTransportTripsTruckDriverDao.update(pdTransportTripsTruckDriver);
        return this.queryById(pdTransportTripsTruckDriver.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdTransportTripsTruckDriverDao.deleteById(id) > 0;
    }
}
